"use strict";

const CACHE_PATH = 'cache'
const SQL_PATH = CACHE_PATH + '/AT.sqlite3';

const fs = require("fs");

if(!fs.existsSync(CACHE_PATH)) fs.mkdirSync(CACHE_PATH);

const BACKUP_INTERVAL = 10 * 60 * 1000; // backup pre 10min 
setInterval(()=>{
    fs.copyFileSync(SQL_PATH, `${SQL_PATH}.${Date.now()}.bak`,fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE);
},BACKUP_INTERVAL);


/* =======  Koa Server ================= */
const Koa = require('koa');
const app = new Koa();
const KoaBody = require('koa-body');
const Websocket = require('koa-easy-ws');

const { router } = require('./src/back/action/router');

app.use(Websocket())
    .use(KoaBody())
    .use(router.routes())
    .use(router.allowedMethods());

app.listen(80);

